import Vue from 'vue'
import store from './store'
import Router from 'vue-router'
import Home from './views/Home.vue'

// 处理点击当前路由时报错的问题
const routerPush = Router.prototype.push
Router.prototype.push = function (location) {
    if (window.$showMessage) {
        window.$showMessage = false
    }
    return routerPush.call(this, location).catch(error => error);
}

Vue.use(Router)

const router = new Router({
    routes: [
        {
            path: '/',
            name: 'Home',
            component: Home
        },
        {
            path: '/LearningHome',
            // route level code-splitting
            // this generates a separate chunk (about.[hash].js) for this route
            // which is lazy-loaded when the route is visited.
            component: () => import('./views/LearningHome.vue'),
            children: [
                {
                    path: '',
                    component: () => import('./views/LearningHome/Learning.vue'),
                    children: [
                        {
                            path: '',
                            component: () => import('./views/LearningHome/Learning/Home.vue')
                        },
                        {
                            path: 'Learning/CourseIntroduction',
                            component: () => import('./views/LearningHome/Learning/CourseIntroduction.vue')
                        },
                        {
                            path: 'Learning/VideoCourse',
                            component: () => import('./views/LearningHome/Learning/VideoCourse.vue')
                        },
                        {
                            path: 'Learning/CoursePractice',
                            component: () => import('./views/LearningHome/Learning/CoursePractice.vue')
                        },
                        {
                            path: 'Learning/StudyNote',
                            component: () => import('./views/LearningHome/Learning/StudyNote.vue')
                        }
                    ]
                },
                {
                    path: 'OnlineExams',
                    component: () => import('./views/LearningHome/OnlineExams.vue'),
                    children: [
                        {
                            path: '',
                            component: () => import('./views/LearningHome/OnlineExams/ExamCenter.vue')
                        },
                        {
                            path: 'ExamHome',
                            component: () => import('./views/LearningHome/OnlineExams/Home.vue')
                        },
                        {
                            path: 'ExamInstructions',
                            component: () => import('./views/LearningHome/OnlineExams/ExamInstructions.vue')
                        },
                        {
                            path: 'StartExam',
                            component: () => import('./views/LearningHome/OnlineExams/StartExam.vue')
                        },
                        {
                            path: 'LearningServices',
                            component: () => import('./views/LearningHome/LearningServices.vue')
                        },
                        {
                            path: 'SurveyDetail',
                            component: () => import('./views/LearningHome/SurveyDetail.vue')
                        }
                    ]
                },
                {
                    path: 'Subject',
                    component: () => import('./views/LearningHome/Subject.vue'),
                    children: [
                        {
                            path: '',
                            component: () => import('./views/LearningHome/Subject/Home.vue')
                        }
                    ]
                },
                {
                    path: 'NoticeCenter',
                    component: () => import('./views/LearningHome/NoticeCenter.vue'),
                    children: [
                        {
                            path: '',
                            component: () => import('./views/LearningHome/NoticeCenter/Home.vue')
                        },
                        {
                            path: 'Detail',
                            component: () => import('./views/LearningHome/NoticeCenter/Detail.vue')
                        }
                    ]
                },
                {
                    path: 'LearningSubject',
                    component: () => import('./views/LearningHome/Subject/LearningSubject.vue')
                },
                {
                    path: 'LearningCommunity',
                    name: 'LearningCommunity',
                    component: () => import('./views/LearningHome/LearningCommunity.vue')
                },
                {
                    path: 'PersonalCenter',
                    name: 'PersonalCenter',
                    component: () => import('./views/LearningHome/PersonalCenter.vue')
                },
                {
                    path: 'PolicyInterpretation',
                    component: () => import('./views/LearningHome/PolicyInterpretation.vue'),
                    children: [
                        {
                            path: '',
                            component: () => import('./views/LearningHome/Policy/Home.vue')
                        },
                        {
                            path: 'PolicyDetail',
                            component: () => import('./views/LearningHome/Policy/Detail.vue')
                        }
                    ]
                },
                {
                    path: 'PoliticalWorkPlan',
                    name: 'PoliticalWorkPlan',
                    component: () => import('./views/LearningHome/PoliticalWorkPlan.vue')
                },
                {
                    path: 'Search',
                    name: 'Search',
                    component: () => import('./views/LearningHome/Search/Index.vue')
                },
                {
                    path: 'PoliticalNews',
                    component: () => import('./views/LearningHome/PoliticalNews.vue'),
                    children: [
                        {
                            path: '',
                            component: () => import('./views/LearningHome/Policy/NewsHome.vue')
                        },
                        {
                            path: 'NewsDetail',
                            component: () => import('./views/LearningHome/Policy/NewsDetail.vue')
                        }
                    ]
                },
                {
                    path: 'StudentsRank',
                    name: 'StudentsRank',
                    component: () => import('./views/LearningHome/StudentsRank.vue')
                },
                {
                    path: 'DeptRank',
                    name: 'DeptRank',
                    component: () => import('./views/LearningHome/DeptRank.vue')
                },
                {
                    path: 'Psychological',
                    component: () => import('./views/LearningHome/Psychological/index.vue'),
                    children: [
                        {
                            path: '',
                            component: () => import('./views/LearningHome/Psychological/Psychological.vue')
                        },
                        {
                            path: 'PersonalProfile',
                            component: () => import('./views/LearningHome/Psychological/PersonalProfile.vue')
                        },
                        {
                            path: 'StartEvaluation',
                            component: () => import('./views/LearningHome/Psychological/StartEvaluation.vue')
                        },
                        {
                            path: 'StartSchool',
                            component: () => import('./views/LearningHome/Psychological/StartSchool.vue')
                        },
                        {
                            path: 'StartCase',
                            component: () => import('./views/LearningHome/Psychological/StartCase.vue')
                        },
                        {
                            path: 'militaryNews',
                            component: () => import('./views/LearningHome/Psychological/MilitaryNews.vue')
                        }
                    ]
                }
            ]
        },
        {
            path: '/Cinziqao',
            name: '/CinziqaoHome',
            component: () => import('./views/Cinziqao/CinziqaoHome.vue'),
            children: [
                {
                    path: '',
                    component: () => import('./views/Cinziqao/Education.vue'),
                    children: [
                        {
                            path: '',
                            component: () => import('./views/Cinziqao/Education/Home.vue')
                        },
                        {
                            path: 'Detail',
                            component: () => import('./views/Cinziqao/Education/Detail.vue')
                        }
                    ]
                },{
                    path: 'Faq',
                    component: () => import('./views/Cinziqao/Faq.vue'),
                    children: [
                        {
                            path: '',
                            component: () => import('./views/Cinziqao/Faq/Home.vue')
                        },
                        {
                            path: 'Detail',
                            component: () => import('./views/Cinziqao/Faq/Detail.vue')
                        }
                    ]
                },
                {
                    path: 'Test',
                    component: () => import('./views/Cinziqao/Test.vue'),
                    children: [
                        {
                            path: '',
                            component: () => import('./views/Cinziqao/Test/Home.vue')
                        },
                        {
                            path: 'Detail',
                            component: () => import('./views/Cinziqao/Test/Detail.vue')
                        }
                    ]
                },
                {
                    path: 'Consult',
                    component: () => import('./views/Cinziqao/Consult.vue'),
                    children: [
                        {
                            path: '',
                            component: () => import('./views/Cinziqao/Consult/Home.vue')
                        },
                        {
                            path: 'Detail',
                            component: () => import('./views/Cinziqao/Consult/Detail.vue')
                        }
                    ]
                },
                {
                    path: 'Train',
                    component: () => import('./views/Cinziqao/Train.vue')
                },
                {
                    path:"PersonalCenter",
                    component: () => import('./views/Cinziqao/PersonalCenter.vue'),
                    children: [
                        {
                            path: '',
                            component: () => import('./views/Cinziqao/PersonalCenter/Home.vue')
                        },
                        {
                            path: 'Detail',
                            component: () => import('./views/Cinziqao/PersonalCenter/Detail.vue')
                        }
                    ]
                }, 
                {
                    path: 'Game',
                    component: () => import('./views/Cinziqao/Game.vue')
                },
            ]
        },
    ]
})

router.beforeEach((to, from, next) => {
    if (to.path !== '/' && !utils.getItem('userInfo')) {
        store.commit('showLoginDialog', true)
        next(false)
    } else {
        next()
    }
})

export default router
